import http from "./http.js";
//引用md5对密码进行加密
import md5 from "js-md5";

// ======================= 注册接口
// 这样写，在组件中调用接口，就相当于调用方法
export function register(name, pwd) {
  return http.post("/user/register", {
    loginName: name,
    password: pwd,
  });
}

// ======================= 登录接口
export function login(name, pwd) {
  return http.post("/user/login", {
    loginName: name,
    passwordMd5: md5(pwd),
  });
}

//获取首页信息
export function getIndexInfo() {
  return http.get("index-infos");
}

// 根据商品ID获取详情
export function getInfoData(id) {
    return http.get("/goods/detail/" + id)
}

//获取购物车信息
export function getShopCart() {
  return http.get("shop-cart");
}

//添加购物车
export function addShopCart(id,count) {
  return http.post("shop-cart", {
    goodsId: id,
    goodsCount: count,
  });
}

//修改商品数量
export function EditShopCart(id, count) {
  return http.put("shop-cart", {
    cartItemId: id,
    goodsCount: count,
  });
}

//获取地址列表
export function APIgetAddressList() {
  return http.get("address");
}

//新增地址
export function APIaddAddress(obj) {
  return http.post("address",obj);
}

//获取某个地址详情
export function APIgetAddressDetail(id) {
  return http.get("address/"+id);
}

//修改某个地址
export function APIeditAddress(obj) {
  return http.put("address", obj);
}


//删除某个地址
export function APIdelAddress(id) {
  return http.delete("address/"+id);
}

//生成订单页面
export function APIgetOrder(ids) {
  return http.get("/shop-cart/settle", {
    params: {
      cartItemIds: ids,
    },
  });
}

//生成订单号
export function APIsaveOrder(addressId, cartItemIds) {
  return http.post("saveOrder", {
    addressId,
    cartItemIds,
  });
}

//支付
//paySuccess?orderNo=16722188332269579&payType=1
export function APIpaySuccess(no,types) {
  return http.get("/paySuccess", {
    params: {
      orderNo: no,
      payType: types,
    },
  });
}

//订单分页
//order?pageNumber=1&status=
export function APIgetOrderList(page, sta = '') {
  return http.get("/order", {
    params: {
      pageNumber:page,
      status:sta,
    },
  });
}

//获取个人信息
export function APIgetUserInfo() {
  return http.get("/user/info");
}


 //获取分类页信息
 export function APIgetCategoryInfo() {
   return http.get("/categories");
 }

